package StringStudy;

import java.util.Scanner;

//手机号中4到7位替换
public class StringLearn4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的手机号");
        String sjh = scanner.next();
        System.out.println("a(sjh) = " + a(sjh));
        System.out.println("b(sjh) = " + b(sjh));
        c();
    }

    //1
    public static String a(String sjh) {
        String res = "";
        sjh = sjh.replace(sjh.substring(3, 7), "****");
        System.out.println("sjh = " + sjh);
        for (int i = 0; i < sjh.length(); i++) {
            if (i >= 3 && i < 7) {
                res += "*";
            } else {
                res += sjh.charAt(i);
            }
        }
        System.out.println("res = " + res);
        return sjh;
    }


    //2
    public static String b(String sjh) {
        StringBuilder stringBuilder = new StringBuilder(sjh);
        StringBuilder sjh1 = stringBuilder.replace(3, 7, "****");
        return sjh1.toString();
    }

    //3
    public static void c() {
        String num;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个手机号码");
        num = scanner.next();
        System.out.println("num = " + num);
        char[] num1 = num.toCharArray();
        for (int i = 3; i <= 6; i++) {
            num1[i] = '*';
        }
        String num2 = new String(num1);
        System.out.println("num2=" + num2);
    }
}
